home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group97a.txt
/
000033_icon-group-sender _Mon Feb 3 10:56:44 1997.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
3KB
Received: by cheltenham.cs.arizona.edu; Mon, 3 Feb 1997 13:13:43 MST
Date: Mon, 3 Feb 1997 10:56:44 -0800
Message-Id: <199702031856.KAA21895@dfw-ix3.ix.netcom.com>
X-Sender: bobalex@popd.ix.netcom.com
X-Mailer: Windows Eudora Pro Version 2.1.2
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
To: Junrong Yuan <joan@cs.ucr.edu>, Icon Group <icon-group@cs.arizona.edu>
From: Bob Alexander <bobalex@ix.netcom.com>
Subject: Re: Icon Tables
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 2588
At 03:06 PM 2/2/97 -0800, Junrong Yuan wrote:
> I have a question about Icon data structure of 'table'. As I
>understand it, a table is a 2D array that has a 'key', and a 'value'
That's one way of looking at tables. However, I prefer to think of them as
one-dimensional "arrays", with elements indexed by *any* datatype rather
than by an integer. The table syntax in Icon supports that mental image by
using a "subscripting" notation (myTable["abc"]).
>I wonder what kind of types that the 'value' field support. To be more
>specific, does it support 'record' or 'list'?
The values in tables can be of any Icon datatype, including records, lists,
tables, files, what-have-you. For that matter, keys can be of any datatype,
too. Strings are probably the most commonly-used, but keys can also be
integers, files, etc. Read carefully the rules about the "===" comparison
operator to see exactly how keys are determined to be "equal" for various
datatypes (for example, lists are "===" only if they are the *same* list,
not just a similar list).
>The Icon book
>said it can be used to implement symbol tables, etc. In the case of symbol
>table, a key may correspond to several attributes, I am thinking of
>putting all the attributes in a record, but I couldn't find a way to store
>a record as 'value' filed in a table.
Here's how to do that:
- Declare the record. This must be outside of any procedure.
record SymTableEntry(field1,field2) # declare the record
- Create the table. This must be in a procedure, and should be executed
only once. Note that you might want your symbol table to be global, so
it should be declared as such.
global SymTable # this declaration must be outside of any procedure
...
SymTable := table() # this must be in a procedure
- Here is the code to create an entry record and add it to the table
symbol := "abc"
SymTable[symbol] := SymTableEntry(123,456)
> Another question: does list support search functions? If I have
>a list of records, and I want to find a given item in the list that has a
>given value in a certain record field. What shall I do ?
There is no list search function in Icon. However, such things can be coded
so succinctly in Icon that they really aren't as useful as in some other
languages. Here is one compact way to do it:
if (foundEntry := !myList).aField == "xyz" then
<deal with found record, "foundEntry">
else
<deal with no such element in list>
Hope this helps.
-- Bob Alexander
bobalex@ix.netcom.com